package com.dcy.principle.inversion.improve;

/**
 * @Author：dcy
 * @Description:
 * @Date: 2021/1/18 15:17
 */
public class DependencyInversion {
    public static void main(String[] args) {
        Person person = new Person();
        person.receive(new Email());
        person.receive(new WeiXin());
    }
}


interface IReceiver {
    String getInfo();
}

class Email implements IReceiver {

    @Override
    public String getInfo() {
        return "点子邮件信息：hello，world";
    }
}

class WeiXin implements IReceiver {

    @Override
    public String getInfo() {
        return "微信信息：hello，ok";
    }
}


/**
 * 完成Person接收消息的功能
 * 方式2完成
 */
class Person {
    /**
     * 是对接口的依赖
     *
     * @param iReceiver
     */
    public void receive(IReceiver iReceiver) {
        System.out.println(iReceiver.getInfo());
    }
}
